<template>
	<div class="writeform">
		<form class="form-cont" v-if="$route.params.param == 'NM'">
			<div class="form-group formline">
				<label>标题：</label>
				<input type="text" name="title" class="form-control" placeholder="请输入标题">
			</div>
			<div class="form-group">
				<label class="pb10">事件描述：</label>
				<textarea name="title" rows="3" class="form-control" placeholder="请填写事件描述"></textarea>
			</div>
			<div class="form-group">
				<label class="pb10">解决办法：</label>
				<textarea name="title" rows="3" class="form-control" placeholder="请填写解决方法"></textarea>
			</div>
			<div class="form-group">
				<label class="pb10">教训：</label>
				<textarea name="title" rows="3" class="form-control" placeholder="请填写教训"></textarea>
			</div>
			<div class="form-group formline">
				<label>图片标题：</label>
				<input name="title" type="text" class="form-control" placeholder="请输入图片标题">
			</div>
			<div class="form-group uploadimage" id="uploadimage">
				<ul>
					<li v-for="img in imgs">
						<img :src="img" />
					</li>
				</ul>
	        	<a class="companypic" id="chooseImages" @click="getSig()">
	        		<i class="ion ion-android-add fontcompany"></i>
	        		<span class="bluecolor block">点击上传照片</span>
	        	</a>
       		</div>
       		<div class="savebtn">
	       		<button type="button" class="">保存</button>
	       		<button type="button" class="">保存并提交</button>
	   		</div>
		</form>
	</div>
</template>

<script type="text/javascript">

	import wx from 'weixin-js-sdk'

	import jssdk from '../../assets/js/jssdk/wxJSSDK'

	export default {
		data () {
			return {
				imgs:[],
				serverIds:'',
				idx:0
			}
		},
		mixins:[jssdk],
		mounted() {
			console.log(this);
			console.log(jssdk);
			this.init();
			// alert(window.location.href)
		},
		methods: {
			getSig() {
				var vue = this;
				var chooseImageID = [];
				var imageId = document.getElementById('chooseImages');
				this.imageApi({
					chooseImage:{
						count:6,
						success:function(res){
							chooseImageID = res.localIds;
							vue.serverIds = '';
							vue.imgs = chooseImageID;
							// vue.imglength = vue.imgs.length;
							vue.syncUpload(chooseImageID);
							console.log("gongsi------------" + chooseImageID);
						}
					}
				})
			},
			syncUpload (localIds){
				var vue = this;
				this.imageApi({
					uploadImage:{
						localId:localIds[vue.idx].toString(),
						success:function(res){
							vue.idx++;
							vue.serverIds+=res.serverId+',';
							if(vue.idx<localIds.length){
								vue.syncUpload(localIds);
							}else{
								vue.idx = 0;
							}
						}
					}
				})
			}
		}
	}
</script>